//utf-8

//选择合约
function toAddContract(){
	
	var dialogStruct={
			'display':contextRootPath+'/tCMmContract/prepareExecute/toSelectContract',
			'width':1000,
			'height':800,
			'title':'选择合约',
			'isIframe':'false',
			'buttons':[
			           {'text':'确定','action':doAddFromContractSure,'isClose':true},
			  		   {'text':'关闭','isClose':true}
			]
		};
		
		var dialogAdd =jyDialog(dialogStruct).open();

	
}

//增加贷款
function toAddDataLoan(){
	var value = $('#dtocooperorgCode').val();
	if(value==""|| null ==value){
		alert("请选择载入合约信息！");
		return;
	}
	var creditPackageName = $('#dealPackage').val();
	var packageRule = $('#packageRule').val();
	var raisePlan = $('#raisePlan').val();
	var statementDateStart = $('#statementDateStart').val();
	var statementDateEnd = $('#statementDateEnd').val();
	var statementDateEnd = $('#statementDateEnd').val();
	var publicRepayType = $('#publicRepayType').val();
	if(value!=null && value!=""){
		
		if(packageRule=="01"){
			if(null==creditPackageName ||""==creditPackageName){
				alert("请选择或者填写包名！");
				return;
			}
			
			if(null==statementDateStart || ""==statementDateStart){
				alert("请选择账单起始日！");
				return;
			}
			
			if(null==statementDateEnd || ""==statementDateEnd){
				alert("请选择账单结束日！");
				return;
			}
			
			if(statementDateStart>statementDateEnd){
				alert("账单起始日不能大于账单结束日！");
				return;
			}
			
			if(null==publicRepayType || ""==publicRepayType){
				alert("请选择还款方式！");
				return;
			}
		}
		if("TBJ"==value&&true==cimsConstant.TBJ_CHECK_RAISE){
			if(null==raisePlan||""==raisePlan||raisePlan=="0"){
				alert("请选择募集计划！");
				return ;
			}
		}
	}
	var dialogStruct={
			'display':contextRootPath+'/tCMmQuotaLoanDetail/prepareExecute/toAddLoanDetail',
			'width':1100,
			'height':600,
			'title':'贷款列表',
			'isIframe':'false',
			'buttons':[
			         {'text':'确定','action':doSureLoan,'isClose':true},
			  		 {'text':'关闭','isClose':true}
			]
		};
		
		var dialogAdd =jyDialog(dialogStruct).open();
}

//确认贷款
function doSureLoan(obj){
	
	var v_ids = iframeLoanDetail.iframeObj["table"].getSelectedIds().join(",");
	var quotaCodeIsAll = $('input[name=quotaCodeIsAll]:checked').val();
	var quotaCode = $('input[name=quotaCode]').val();
	//如果没有选中 数据则
	if(v_ids == ""&&quotaCodeIsAll!="01"){
		alert("请选择贷款!");
		return;
	}
	if(quotaCodeIsAll=='01'&&quotaCode==""){
		alert("按申请流水交易需要填写申请流水号！");
		return;
	}
	if(quotaCodeIsAll!='01'){
		quotaCodeIsAll="00";
	}
	var table=iframeLoanDetail.iframeObj["table"];
	var contractNos = table.getSelectedObjs("contractNo");
	contractNos = "" + contractNos;
	var ids = table.getSelectedObjs("id");
	ids = "" + ids;
	var dealCode = $('#dealCode').val();
	var id = $('#idValue').val();
	var valueContractCode = $('#dtocontractCode').val();
	var cooperorgCode = $('#dtocooperorgCode').val();
	var agreementCode = $('#dtoagreementCode').val();
	var statementDateStart = $('#statementDateStart').val();
	var statementDateEnd = $('#statementDateEnd').val();
	var publicRepayType = $('#publicRepayType').val();
	var creditPackageName = $('#dealPackage').val();
	var raisePlanId = $('#raisePlan').val();
	var dataUrl =contextRootPath + "/cooperorgDeal/updateQuotaDetailByLoan";	
	$.ajax({
		url: dataUrl,
		type: 'post',
		dataType: 'json',
		data:{"contractNos":contractNos,
			"qldids":ids,
			"dealCode":dealCode,
			"contractCode":valueContractCode,
			"cooperorgCode":cooperorgCode,
			"agreementCode":agreementCode,
			"id":id,
			"planId":raisePlanId,
			"repayDay":statementDateStart,
			"billDateEnd":statementDateEnd,
			"repayType":publicRepayType,
			"creditPackageName":creditPackageName,
			"quotaCodeIsAll":quotaCodeIsAll,
			"quotaCode":quotaCode},
		success: function(results) {
			var obj = results.data;
			$("#idValue").val(obj.id);
			$("#dealCode").val(obj.dealCode);
			$("#dealDate").val(obj.dealDate);
			initFnLoanDetailView(contractNos);
			$("#creditDetailTable").show();
			LoanValueSum();
			$("#isDelete").val("true");
			$("#packageRule").attr("disabled","disabled");
			$("#raisePlan").attr("disabled","disabled");
			$("#statementDateStart").attr("disabled","disabled");
			$("#statementDateEnd").attr("disabled","disabled");
			$("#publicRepayType").attr("disabled","disabled");
			$("#dealPackage").attr("disabled","disabled");
			alert(results.msg);
			
		}
	});
	
	
	
}

//贷款金额合计
function LoanValueSum(){
	var dealCode = $("#dealCode").val();
	var dataUrl =contextRootPath + "/cooperorgDeal/getDealDetailByLoanTotal";	
	$.ajax({
		url: dataUrl,
		type: 'post',
		dataType: 'json',
		data:{"dealCode":dealCode},
		error: function(result) {
			
			alert("请查看返回数据是否正确：" + result);
		},
		success: function(results) {
			var obj = results.data;
			$("#detialNumber").val(obj.detialNumber);
			$("#sumCreditorValue").val(obj.sumCreditorValue);
		}
	});
}

//确认合约
function doAddFromContractSure(){
	var contractCode = iframeSelectContract.iframeObj["table"].getSelectedObjs("contractCode");
	
	 window.location = contextRootPath+'/tCMmContract/prepareExecute/toBackLoanDetailAdd?contractCode='+contractCode;
	
}

//双击合约
function doAddFromContract(contractCode){
		
	 window.location = contextRootPath+'/tCMmContract/prepareExecute/toBackLoanDetailAdd?contractCode='+contractCode;
	
}

//查询债权包隐藏标签
var selectOptions=[];	
function searchCreditPackage(selectID,updatePackageValue,type){
	var value = $('#dtocooperorgCode').val();
	if(value==""|| null ==value){
		return;
	}
	
	var valueCooperorgCode = $('#dtocooperorgCode').val();
	var dataUrl = contextRootPath + '/cooperorgDeal/getPackageList?cooperorgCode=' + valueCooperorgCode + "&pagType=" + cimsConstant.LOAN_RESOURCE;
	$('#creditPackage').html("<option id='selectValue' value='0'>请选择</option>");
	$.ajax({
		url: dataUrl,
		type: 'get',
		dataType: 'json',
		data:'',
		error: function(result) {
			alert("请查看返回数据是否正确：" + result);
		},
		success: function(results) {
			var result=results.data;
			var j;
			var resultLength = result.length - 1;
			for (j = 0; j <= resultLength; j++) {
				$('#creditPackage').append("<option name='"+result[j].creditPackageName+"' value='"+result[j].billDate+":"+result[j].billDateEnd+":"+result[j].repayType+"'>"+result[j].creditPackageName+"</option>");
				selectOptions.push(result[j].creditPackageName);
			}
			completePackage(selectOptions,selectID,updatePackageValue,type);
		}
	});

}
//查询铜板街募集计划
function searchRaisePlan(){
	var valueCooperorgCode = $('#dtocooperorgCode').val();
	var defaultPlanId = $('#defaultPlanId').val();//募集计划默认值。新增:-1 其他为：null或者具体值
	if("TBJ"==valueCooperorgCode&&true==cimsConstant.TBJ_CHECK_RAISE){
		$("#raisePlan").show();
		$("#sendBtn").show();//推送按钮显示
		var dataUrl = contextRootPath + '/raisePlanCtrl/getSelectRaisePlanList?raiseStatus=' + cimsConstant.RAISE_STATUS_BEGIN;
		//判断完成按钮是否显示
		if(null!=defaultPlanId&&"-1"==defaultPlanId){//新增
			$("#finishBtn").show();//铜板街显示完成按钮
		}else{
			dataUrl = contextRootPath + '/raisePlanCtrl/getSelectAllRaisePlanList';//获取募集计划下拉所有数据
			var dealStatus = $("#cooperativeAgencyDealStatus").val();
			if('01'==dealStatus||'02'==dealStatus){
				$("#finishBtn").show();//铜板街显示完成按钮
			}else{
				$("#isFinishEd").val("true");
				$("#finishBtn").hide();//完成按钮隐藏
				$("#saveBtn").show();//保存按钮显示
				$("#addDataLoan").show();//新增按钮显示
				if(null!=defaultPlanId && ""!=defaultPlanId){
					$("#saveBtn").hide();//保存按钮隐藏
					$("#addDataLoan").hide();//新增按钮隐藏
				}
			}
		}
		$('#raisePlan').html("<option  name='请选择' value='0'>请选择</option>");
		$.ajax({
			url: dataUrl,
			type: 'get',
			dataType: 'json',
			data:'',
			error: function(result) {
				alert("请查看返回数据是否正确：" + result);
			},
			success: function(results) {
				var result=results.data;
				var resultLength = result.length - 1;
				var j;
				if(null!=defaultPlanId&&"-1"==defaultPlanId){//新增
					for (j = 0; j <= resultLength; j++) {
						$('#raisePlan').append("<option value='"+result[j].planId+"'>"+result[j].planName+"_"+result[j].planId+"</option>");
					}
				}else{//修改操作
					for (j = 0; j <= resultLength; j++) {
						if(defaultPlanId!=null&&defaultPlanId!=""&&defaultPlanId==result[j].planId){
							$('#raisePlan').append("<option selected='selected' value='"+result[j].planId+"'>"+result[j].planName+"_"+result[j].planId+"</option>");
						}else{
							$('#raisePlan').append("<option value='"+result[j].planId+"'>"+result[j].planName+"_"+result[j].planId+"</option>");
						}
					}
				}
				
			}
		});
	}else{
		$("#raisePlan").hide();
		$("#raisePlanSpan").hide();
		//$("#finishBtn").hide();//完成按钮隐藏
		$("#sendBtn").hide();//推送按钮隐藏
	}
}
//保存审批交互流水
function saveLoanDeal(){
	
	var valueCooperorgCode = $('#dtocooperorgCode').val();
	var valueContractCode = $('#dtocontractCode').val();
	var valueQuotaSum = $('#dtoquotaSum').val();
	var creditPackageName = $('#dealPackage').val();
	var dealCode = $('#dealCode').val();
	var id = $('#idValue').val();
	var sumCreditorValue = $('#sumCreditorValue').val();
	var detialNumber = $('#detialNumber').val();
	var dealType = $('#dealType').val();
	var dtoagreementCode = $('#dtoagreementCode').val();
	var creditPackage = $('#creditPackage').val();
	var packageRule = $('#packageRule').val();
	var dealDate = $('#dealDate').val();
	var cooperorgType = $('#cooperorgType').val();
	var raisePlan = $('#raisePlan').val();
	var defaultPlanId = $('#defaultPlanId').val();
	var statementDateStart = $('#statementDateStart').val();
	var statementDateEnd = $('#statementDateEnd').val();
	var publicRepayType = $('#publicRepayType').val();
	if(null==dealType||""==dealType){
		alert("请选择交易类型！");
		return;
	}
	
	if(null==valueCooperorgCode||""==valueCooperorgCode){
		alert("请选择合约！");
		return;
	}
	
	if(packageRule=="01"){
		if(null==creditPackageName ||""==creditPackageName){
			alert("请选择或者填写包名！");
			return;
		}
		
		if(null==statementDateStart || ""==statementDateStart){
			alert("请选择账单起始日！");
			return;
		}
		
		if(null==statementDateEnd || ""==statementDateEnd){
			alert("请选择账单结束日！");
			return;
		}
		
		if(statementDateStart>statementDateEnd){
			alert("账单起始日不能大于账单结束日！");
			return;
		}
		
		if(null==publicRepayType || ""==publicRepayType){
			alert("请选择还款方式!");
			return;
		}
	}
	
	
	if(null==dealCode||""==dealCode){
		alert("请选择贷款！");
		return;
	}
	//如果是铜板街募集计划是必须的，否则给空
	if("TBJ"==valueCooperorgCode&&true==cimsConstant.TBJ_CHECK_RAISE){
		if(null!=defaultPlanId&&"-1"==defaultPlanId){//铜板街新增判断募集计划
			if(null==raisePlan||""==raisePlan||"0"==raisePlan){
				alert("请选择募集计划！");
				return ;
			}
		}else{//铜板街修改判断募集计划
			raisePlan=defaultPlanId;
		}
	}else{
		raisePlan="";
	}
	
	var dataUrl =contextRootPath + "/cooperorgDeal/saveCooperorgDeal";
	if(confirm("确认保存！")){
		$.ajax({
			url: dataUrl,
			type: 'post',
			dataType: 'json',
			data:{"cooperorgCode":valueCooperorgCode,
				  "contractCode":valueContractCode,
				  "planSellSum":valueQuotaSum,
				  "creditPackageName":creditPackageName,
				  "dealCode":dealCode,
				  "id":id,
				  "sumCreditorValue":sumCreditorValue,
				  "detialNumber":detialNumber,
				  "dealType":dealType,
				  "agreementCode":dtoagreementCode,
				  "packageRule":packageRule,
				  "dealDate":dealDate,
				  "billDate":statementDateStart,
				  "billDateEnd":statementDateEnd,
				  "repayType":publicRepayType,
				  "isFinish":"N",
				  "planId":raisePlan,
				  "cooperorgType":cooperorgType},
			success: function(results) {
				$("#isDeleteAndIsExport").val("true");
				$("#dealPackage").attr("disabled","disabled");
				$("#publicRepayType").attr("disabled","disabled");
				var winObj = parent.tabs.getTabWinByTitle("审批交互");
				if(winObj)
				winObj.location.reload();
				alert("保存成功！");
				
			}
		});
	}
}
//完成操作
function doFinish(){
	
	var valueCooperorgCode = $('#dtocooperorgCode').val();
	var valueContractCode = $('#dtocontractCode').val();
	var valueQuotaSum = $('#dtoquotaSum').val();
	var creditPackageName = $('#dealPackage').val();
	var dealCode = $('#dealCode').val();
	var id = $('#idValue').val();
	var sumCreditorValue = $('#sumCreditorValue').val();
	var detialNumber = $('#detialNumber').val();
	var dealType = $('#dealType').val();
	var dtoagreementCode = $('#dtoagreementCode').val();
	var creditPackage = $('#creditPackage').val();
	var packageRule = $('#packageRule').val();
	var dealDate = $('#dealDate').val();
	var cooperorgType = $('#cooperorgType').val();
	var raisePlan = $('#raisePlan').val();
	var defaultPlanId = $('#defaultPlanId').val();
	if(null==dealType||""==dealType){
		alert("请选择交易类型！");
		return;
	}
	
	if(null==valueCooperorgCode||""==valueCooperorgCode){
		alert("请选择合约！");
		return;
	}
	
	if(packageRule=="01"){
		if(null==creditPackageName ||""==creditPackageName){
			alert("请选择或者填写包名！");
			return;
		}
	}
	
	
	if(null==dealCode||""==dealCode){
		alert("请选择贷款！");
		return;
	}
	//如果是铜板街募集计划是必须的，否则给空
	var isJjFlag = true;
	if("TBJ"==valueCooperorgCode&&true==cimsConstant.TBJ_CHECK_RAISE){
		if(null!=defaultPlanId&&"-1"==defaultPlanId){//铜板街新增判断募集计划
			if(null==raisePlan||""==raisePlan||"0"==raisePlan){
				alert("请选择募集计划！");
				return ;
			}
		}else{//铜板街修改判断募集计划
			raisePlan=defaultPlanId;
		}
		//检验铜板街该募集编号下的贷款是否全部进件完成
		$.ajax({
			url: contextRootPath + "/raisePlanCtrl/getjMsgByPlanId",
			type: 'post',
			dataType: 'json',
			data:{"planId":raisePlan},
			async:false,
			error: function(result) {
				alert("请查看返回数据是否正确：" + result);
				isJjFlag = false;
				return ;
			},
			success: function(results) {
				var result=results.data;
				var resultLength = result.length;//有值：代表有未完成的进件
				if(resultLength>0){
					alert("进件信息未全部推送完毕！");
					isJjFlag = false;
					return false;
				}
			}
		});
	}else{
		raisePlan="";
	}
	var dataUrl =contextRootPath + "/cooperorgDeal/saveCooperorgDeal";
	if(isJjFlag){
		if(confirm("确认完成！")){
			$.ajax({
				url: dataUrl,
				type: 'post',
				dataType: 'json',
				data:{"cooperorgCode":valueCooperorgCode,
					  "contractCode":valueContractCode,
					  "planSellSum":valueQuotaSum,
					  "creditPackageName":creditPackageName,
					  "dealCode":dealCode,
					  "id":id,
					  "sumCreditorValue":sumCreditorValue,
					  "detialNumber":detialNumber,
					  "dealType":dealType,
					  "agreementCode":dtoagreementCode,
					  "packageRule":packageRule,
					  "dealDate":dealDate,
					  "isFinish":"Y",
					  "planId":raisePlan,
					  "cooperorgType":cooperorgType},
					  
				error: function(result) {
					alert("请查看返回数据是否正确：" + result);
				},
				success: function(results) {
					$("#isDeleteAndIsExport").val("true");
					$("#saveBtn").hide();//保存按钮
					$("#finishBtn").hide();//完成按钮
					$("#addDataLoan").hide();//新增债权按钮addDataLoan
					$("#spanCode").hide();//导入合约按钮spanCode
					$("#isFinishEd").val("true");
					var winObj = parent.tabs.getTabWinByTitle("审批交互");
					if(winObj)
						winObj.location.reload();
					alert("保存成功！");
					
				}
			});
		}
	}
}
/**
 * 铜板街推送放款信息
 */
function doSend(){
	var raisePlan = $('#raisePlan').val();
	var isFinishEd = $("#isFinishEd").val();
	
	if("false"==isFinishEd){
		alert("必须点击完成之后才能进行推送！");
		return ;
	}
	
	if(confirm("确认推送！")){
		$.ajax({
			url: contextRootPath + "/cooperorgDeal/doSend",
			type: 'post',
			dataType: 'json',
			data:{"planId":raisePlan},
			error: function(result) {
				alert("请查看返回数据是否正确：" + result);
			},
			success: function(results) {
				var status = results.status;
				var msg = results.msg;
				if("Y"==status){
					initFnLoanDetailView();
					alert("贷款审批通过推送成功！");
				}else if("N"){
					alert(msg);
				}
			}
		});
	}
}

//保存报盘管理流水
function saveLoanManage(){
	
	var valueCooperorgCode = $('#dtocooperorgCode').val();
	var valueContractCode = $('#dtocontractCode').val();
	var valueQuotaSum = $('#dtoquotaSum').val();
	var creditPackageName = $('#creditPackageWrite').val();
	var dealCode = $('#dealCode').val();
	var id = $('#idValue').val();
	var sumCreditorValue = $('#sumCreditorValue').val();
	var detialNumber = $('#detialNumber').val();
	var dealType = $('#dealType').val();
	var dtoagreementCode = $('#dtoagreementCode').val();
	var creditPackage = $('#creditPackage').val();
	var packageRule = $('#packageRule').val();
	if(null==dealType||""==dealType){
		alert("请选择交易类型！");
		return;
	}
	
	if(null==valueCooperorgCode||""==valueCooperorgCode){
		alert("请选择合约！");
		return;
	}
	
	if(packageRule=="01"){
		if(null==creditPackageName ||""==creditPackageName){
			alert("请选择或者填写包名！");
			return;
		}
	}
		
	if(null==dealCode||""==dealCode){
		alert("请选择贷款！");
		return;
	}

	var dataUrl =contextRootPath + "/cooperorgDeal/saveCooperorgDeal";
	$.ajax({
		url: dataUrl,
		type: 'post',
		dataType: 'json',
		data:{"cooperorgCode":valueCooperorgCode,
			  "contractCode":valueContractCode,
			  "planSellSum":valueQuotaSum,
			  "creditPackageName":creditPackageName,
			  "dealCode":dealCode,
			  "id":id,
			  "sumCreditorValue":sumCreditorValue,
			  "detialNumber":detialNumber,
			  "dealType":dealType,
			  "agreementCode":dtoagreementCode,
			  "packageRule":packageRule},
		success: function(results) {
			var winObj = parent.tabs.getTabWinByTitle("报盘管理");
			if(winObj)
			winObj.location.reload();
			parent.tabs.close();
		}
	});
}

//贷款包输入
function creditPackageOperation(obj){
	var text = obj.value;
	var selectObj = $("#creditPackage option[name="+obj.value+"]").length;
	var textValue = "" + $("#creditPackage option[name="+obj.value+"]").val();
	
	
	if (selectObj!=0){
			var textValueArray = textValue.split(":");
			$("#statementDateStart").val(textValueArray[0]);
			$("#statementDateEnd").val(textValueArray[1]);
			$("#publicRepayType option[value="+textValueArray[2]+"]").attr("selected","true");
			$('#publicRepayType').attr("disabled","disabled");
			$('#statementDateStart').attr("disabled","disabled");
			$('#statementDateEnd').attr("disabled","disabled");
	}else {
		$('#publicRepayType').removeAttr("disabled");
		$('#statementDateStart').removeAttr("disabled");
		$('#statementDateEnd').removeAttr("disabled");
		$("#statementDateStart").val("");
		$("#statementDateEnd").val("");
	}
	
}

//删除贷款
function deleteLoan(){
	
	var isDelete = $("#isDelete").val();
	if(false==isDelete || "false"==isDelete){
		alert("该信息不可删除！");
		return;
	}
	var v_ids = iframeLoanDetailView.iframeObj["table"].getSelectedIds().join(",");
	var contractNos = iframeLoanDetailView.iframeObj["table"].getSelectedObjs("contractNo").join(",");
	var loanStatus = iframeLoanDetailView.iframeObj["table"].getSelectedObjs("loanStatus").join(",");
	
	//如果没有选中 数据则
	if(v_ids == ""){
		alert("请选择待删除的数据！");
		return;
	}
	//判断状态是否为在途  01为在途
	var complete1 = loanStatus.indexOf('02');//贷款状态：审批通过
	var complete2 = loanStatus.indexOf('03');//贷款状态：审批拒绝
	var complete3 = loanStatus.indexOf('04');//贷款状态：放款成功
	var complete4 = loanStatus.indexOf('05');//贷款状态：放款失败
	var complete5 = loanStatus.indexOf('06');//贷款状态：我司拒绝放款
	if(complete1>-1||complete2>-1||complete3>-1||complete4>-1||complete5>-1){
		alert("只有在途状态才能删除！");
		return;
	}
	if(confirm("您确认要删除选择的数据吗？数据将退回合同调配，无法再新增！")){
        $.ajax({
            type:"POST",
            dataType : "json",
            url:contextRootPath+"/cooperorgDeal/deleteDetailByLoan",
            data:{"intoAppCodes":v_ids,"contractNos":contractNos},
            success:function(msg){
            	alert(msg.msg);
            	var v_status = msg.status;
            	//删除成功后
            	if(v_status.indexOf('ok') >-1){
            		iframeLoanDetailView.iframeObj["table"].removeSelectedRow();
            		LoanValueSum();
            	}
            	
            	
            }
        });
    }
}

/*$(document).ready(function(){
	$('#creditorAffirmRule').attr("disabled","disabled");
});
*/

//导出报盘文件
function exportBpFile(){
	var isDeleteAndIsExport = $("#isDeleteAndIsExport").val();
	if(false==isDeleteAndIsExport||"false"==isDeleteAndIsExport){
		alert("没有数据可导出，请新增！");
		return;
	}
	var dealCode = $('#dealCode').val();
	var url = contextRootPath+'/cooperorgDeal/exportBpFile?dealCode='+dealCode;
	window.location  =url; 

}
//导入回盘文件
function toImportHpFile(){
	
	var valueContractCode = $('#dtocontractCode').val();
	var dealCode = $('#dealCode').val();
	var importUrl = 'cooperorgDeal/importHpFile';
	var dialogStruct={
		'display':contextRootPath+'/common/importExcelFile.jsp?contractCode=' + valueContractCode +'&dealCode='+dealCode+'&importUrl='+importUrl,
		'width':800,
		'height':400,
		'title':'导入数据',
		'isIframe':'true',
		'buttons':[{'text':'关闭','isClose':true}]
	};
	dialog_import =jyDialog(dialogStruct);
	dialog_import.open();
	
}

//拒绝放款明细
function refusedLend(){
	var isDeleteAndIsExport = $("#isDeleteAndIsExport").val();
	if(false==isDeleteAndIsExport||"false"==isDeleteAndIsExport){
		alert("没有数据可拒绝放款，请新增！");
		return;
	}
	
	var v_ids = iframeLoanDetailView.iframeObj["table"].getSelectedIds().join(",");
	var loanStatus = iframeLoanDetailView.iframeObj["table"].getSelectedObjs("loanStatus").join(",");
	//如果没有选中 数据则
	if(v_ids == ""){
		alert("请选择待拒绝放款的数据！");
		return;
	}
	var complete1 = loanStatus.indexOf('01');//贷款状态：在途
	var complete2 = loanStatus.indexOf('03');//贷款状态：审批拒绝
	var complete3 = loanStatus.indexOf('04');//贷款状态：放款成功
	var complete4 = loanStatus.indexOf('05');//贷款状态：放款失败
	var complete5 = loanStatus.indexOf('06');//贷款状态：我司拒绝放款
	if(complete1>-1||complete2>-1||complete3>-1||complete4>-1||complete5>-1){
		alert("只有审批通过才能拒绝放款！");
		return;
	}
	var url = contextRootPath+"/cooperorgDeal/refusedLendByLoanDetailIds";
	var params = {"ids":v_ids};
	if(confirm("您确认要拒绝放款选择的数据吗？")){
		
		jyAjax(
				url,
				params,
				function(msg){
					//新增成功后，
					alert(msg.msg);
					var v_status = msg.status;
		        	if(v_status.indexOf('ok') >-1){
		        		//新增成功后 刷新页面 或 只查询 id为msg.data['id'] 的  数据
		        		queryData();
		        		alert("拒绝放款成功！");
		        	}
		  	});
		
    }
}

//交易拒绝放款
function refusedDealLend(){
	
	var v_ids = iframeLoanDetailView.iframeObj["table"].getSelectedIds().join(",");
	var dealCode = iframeLoanDetailView.iframeObj["table"].getSelectedObjs("dealCode").join(",");
	
	//如果没有选中 数据则
	if(v_ids == ""){
		alert("请选择待拒绝放款的数据！");
		return;
	}
	if(confirm("您确认要拒绝放款选择的数据吗？")){
        $.ajax({
            type:"POST",
            dataType : "json",
            url:contextRootPath+"",
            data:{"ids":v_ids,
            	  "dealCode":dealCode
            	},
            success:function(msg){
            	alert(msg.msg);
            	var v_status = msg.status;
            	//删除成功后
            	if(v_status.indexOf('ok') >-1){
            		iframeLoanDetailView.iframeObj["table"].removeSelectedRow();
            		alert("拒绝放款成功！");
            	}
            	
            	
            }
        });
    }
}
/**
 * 贷款的费用计算按钮
 */
function feeCalcLoan(){
	
	var dealCode = $('#dealCode').val();
	var costCode = $('#costParameter').val();
	
	if(null==dealCode||dealCode==""){
		alert("交易流水号为空！");
		return;
	}
	$.ajax({
         type:"POST",
         dataType : "json",
         url:contextRootPath+"/tCMmCostParam/calcFeeLoanSum",
         data:{
         	  "dealCode":dealCode,
         	  "costCode":costCode
         	},
         success:function(msg){
         	alert(msg.msg);
         	var v_status = msg.status;
         	if(v_status.indexOf('yes') >-1){
         		initFnLoanDetailView();
         	}
         }
    });
}
//审批交互页面关闭按钮操作
function closeFather(){
	var winObj = parent.tabs.getTabWinByTitle("审批交互");
	if(null==winObj){
		parent.tabs.close();
	}else{
		if(winObj)
		winObj.location.reload();
		parent.tabs.close();
	}
}

//报盘管理页面关闭按钮操作
function closeFatherOffer(){
	var winObj = parent.tabs.getTabWinByTitle("报盘管理");
	if(null==winObj){
		parent.tabs.close();
	}else{
		if(winObj)
		winObj.location.reload();
		parent.tabs.close();
	}
}
